package 笔试题.yingtailai;

import java.util.Scanner;

public class 打印二维数组 {
    public static void main(String[] args) {
        StringBuilder res = new StringBuilder();
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int n = sc.nextInt();
        int[][] nums = new int[m][n];
        for(int i = 0; i < m; i++){
            for(int j = 0; j < n; j++){
                nums[i][j] = sc.nextInt();
            }
        }
        int count = n + m - 1;
        for (int j = 0; j < n; j++) {
            int i = 0, k = j;
            while (i < m && k >= 0) {
                res.append(nums[i++][k--] + ",");
            }
        }
        for (int i = 1; i < m; i++) {
            int j = n - 1, k = i;
            while (k < m && j >= 0) {
                res.append(nums[k++][j--] + ",");
            }
        }
        res.deleteCharAt(res.length() - 1);
        System.out.println(res.toString());
    }
}
